﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace API_CIC.UsuariosRoles
{
    public partial class GestionRoles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        protected void btnIngresar_Click(object sender, EventArgs e)
        {
            CapaControl.cRolesControl.IngresarRol(txtNombre.Text,txtDescripcion.Text,cblPermisos);
            MultiView1.ActiveViewIndex = 1;
            Menu1.Items[0].Selected = true;
            GridView1.DataBind();
        }


       
       

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            LlenarDatosRol();
        }


        /// <summary>
        /// Propósito: Llenar los permisos al seleccionar un rol
        /// </summary>
        private void LlenarDatosRol()
        {

            SGAPFROLE rol = CapaDatos.cRolesDatos.GetRol(Int32.Parse(GridView1.SelectedValue.ToString()));
            System.Collections.IEnumerator enu = rol.SGAPFROL_PERMISOs.GetEnumerator();
            System.Collections.IEnumerator enu2 = cblPermisosModificar.Items.GetEnumerator();
            while (enu2.MoveNext())
                ((ListItem)enu2.Current).Selected = false;
            while (enu.MoveNext())
            {
                cblPermisosModificar.Items.FindByValue(((SGAPFROL_PERMISO)enu.Current).COD_PERMISO.ToString()).Selected = true;
            }
        }

        
        
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            CapaControl.cRolesControl.ModificarRol(GridView1.SelectedValue.ToString(), cblPermisosModificar);

            Response.Redirect(Request.Url.AbsoluteUri);
            MultiView1.ActiveViewIndex = 1;
            GridView1.DataBind();
        }

        
    }
}